import torch
import ChatTTS
from IPython.display import Audio
import torchaudio

model_path = "/data/Model/ChatTTS"

# 初始化ChatTTS
chat = ChatTTS.Chat()
#chat.load_models(source='local',local_path=model_path)
chat.load_model("ModelM/ChatTTS-ModelScope")
# ModelM/ChatTTS-ModelScope
# 定义要转换为语音的文本
texts = ["你好，欢迎使用ChatTTS之ModelScope版!"]

# 生成语音
wavs = chat.infer(texts, use_decoder=True)

# 播放生成的音频
# Audio(wavs[0], rate=24_000, autoplay=True)

# 保存语音文件
torchaudio.save("output.wav", torch.from_numpy(wavs[0]), 24000)